package com.dz.Controller;

import com.dz.domain.user;
import com.dz.userService.impl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@Controller
public class LoginController {

    @Autowired
    UserServiceImpl uService;

    @GetMapping({"/","/index"})
    public String testStart(){
        return "login";
    }

    @PostMapping("/testLogin")
    public String testLogin(user us, Model model){
        System.out.println(us);
        user user = uService.findById(us);
        if (user != null){
            return "redirect:/testGetLogin";
        }else {
            return "login";
        }
    }

    @GetMapping("/testGetLogin")
    public  String testGetLogin(Model model){
        int num = uService.userNum();
        model.addAttribute("num",num);
        return "success";
    }

    @ResponseBody
    @RequestMapping("/testDemo")
    public user testDemo(){
        user us = new user();
        us.setLoginname("张三");
        us.setPassword("来自spring boot的信息");
        return us;
    }

    @ResponseBody
    @RequestMapping("/testVueElement")
    public user testVueElement(){
        user us = uService.findByIdTwo(1);
        return us;
    }


}
